var SnakeTail = Base.extend({
	segments: null,
	segmentsToGrowCount: 0,
	
	constructor: function(x, y)
	{
		this.segments = [];
		this.segments.push(new SnakeSegment(x, y));
		this.segments.push(new SnakeSegment(x, y + SnakeSegment.SIZE));
	},

	destructor: function()
	{
		for (var i in this.segments)
		{
			this.segments[i].removeFromStage();
		}
		this.segments = null;
		this.segmentsToGrowCount = 0;
	},
	
	move: function(coords)
	{
		var segments = this.segments;
		var lastSegmentIndex = segments.length - 1;
		var positionToGrow = new Point(segments[lastSegmentIndex].x, segments[lastSegmentIndex].y);
		for (var i = lastSegmentIndex; i > 0; i--)
		{
			var prevSegments = segments[i - 1];
			segments[i].moveTo(prevSegments.x, prevSegments.y);
		}
		segments[0].moveTo(coords.x, coords.y);
		
		if (this.segmentsToGrowCount > 0)
		{
			segments.push(new SnakeSegment(positionToGrow.x, positionToGrow.y));
			this.segmentsToGrowCount--;
		}
	},
	
	grow: function(segmentsNum)
	{
		this.segmentsToGrowCount += segmentsNum;
	},
	
	containsCoords: function(x, y)
	{
		var contains = false;
		for (var i in this.segments)
		{
			if (this.segments[i].hasCoords(x, y))
			{
				contains = true;
			}
		}
		return contains;
	}
});